﻿using iTFF.WPF.CP;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using iTunesLib;

namespace iTFF.Tests
{
    
    
    /// <summary>
    ///This is a test class for iTunesControlPanelTest and is intended
    ///to contain all iTunesControlPanelTest Unit Tests
    ///</summary>
    [TestClass()]
    public class iTunesControlPanelTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetObjectFromPersistenIDTest
        ///</summary>
        [TestMethod()]
        public void GetObjectFromPersistenIDTest()
        {
            iTunesControlPanel target = new iTunesControlPanel();

            var sampleTrack = TrackConstants.GetSampleLyricsModel();

            var track = target.GetTrackFromPersistentID(sampleTrack.iTunesPersistentID);

            Assert.IsInstanceOfType(track, typeof(IITFileOrCDTrack));

            var fileTrack = (IITFileOrCDTrack)track;

            Assert.AreEqual(sampleTrack.Artist, fileTrack.Artist);
            Assert.AreEqual(sampleTrack.Name, track.Name);

            target.Dispose();
        }

        /// <summary>
        ///A test for GetObjectPersistentID
        ///</summary>
        [TestMethod()]
        public void GetObjectPersistentIDTest()
        {
            iTunesControlPanel target = new iTunesControlPanel();

            var sampleTrack = TrackConstants.GetSampleLyricsModel();

            // get the first library track, playing order
            // in my case Aaron
            var track = target.GetFirstLibraryTrack();

            var actual = target.GetObjectPersistentID(track);

            Assert.AreEqual(sampleTrack.iTunesPersistentID, actual);

            target.Dispose();
        }

        /// <summary>
        ///A test for GetUInt64FromPersistentIDHex
        ///</summary>
        [TestMethod()]
        public void GetUInt64FromPersistentIDHexTest()
        {
            iTunesControlPanel target = new iTunesControlPanel();

            // get the first library track, playing order
            // in my case Aaron
            var track = target.GetFirstLibraryTrack();

            ulong id = target.GetObjectPersistentID(track);

            Assert.AreEqual(id, target.GetUInt64FromPersistentIDHex(TrackConstants.GetSampleHex()));

            target.Dispose();
        }

        /// <summary>
        ///A test for GetHexRepresentationFromPersistentID
        ///</summary>
        [TestMethod()]
        public void GetHexRepresentationFromPersistentIDTest()
        {
            iTunesControlPanel target = new iTunesControlPanel();

            // get the first library track, playing order
            // in my case Aaron
            var track = target.GetFirstLibraryTrack();
            
            // get its persistent ID
            ulong id = target.GetObjectPersistentID(track);

            // verify 
            Assert.AreEqual(TrackConstants.GetSampleHex(), target.GetHexRepresentationFromPersistentID(id), "Persistent ID and hex don't aren't equivalent");

            target.Dispose();
        }

    }
}
